package mypractice;

import java.util.HashSet;
import java.util.Set;

public class Leetcode141 {
/*    public static void main(String[] args) {
        new ListNode()
        hasCycle(head);
    }*/
    public boolean hasCycle(ListNode head) {
        Set<ListNode> seen = new HashSet<>();
        while (head!=null){
            if(!seen.add(head)){
                return true;
            }
            head=head.next;
        }
        return false;
    }
}

// * Definition for singly-linked list.
class ListNode {
    int val;
    ListNode next;

    ListNode(int x) {
        val = x;
        next = null;
    }
}
